Support protobuf fields.#82
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
crates/hamgrd/src/db_structs.rs
Outdated
| @@ -207,19 +208,7 @@ pub fn now_in_millis() -> i64 { | |||
| #[derive(Serialize, Deserialize, SonicDb)] | |||
| #[sonicdb(table_name = "DASH_HA_SET_CONFIG_TABLE", key_separator = ":", db_name = "APPL_DB")] | |||
| pub struct DashHaSetConfigTable { | |||
There was a problem hiding this comment.
Is it necessary to keep DashHaSetConfigTable structure with a single attribute? Can we move the derive macros to HaSetConfig?
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
yue-fred-gao
left a comment
There was a problem hiding this comment.
It looks good in general. Let me review it when I get back.
crates/hamgrd/src/actors/ha_scope.rs
Outdated
|
|
||
| let mut dpu_ha_state_state5 = make_dpu_ha_scope_state("active"); | ||
| dpu_ha_state_state5.ha_term = "2".to_string(); | ||
| dpu_ha_state_state5.ha_term = "active".to_string(); |
There was a problem hiding this comment.
is ha_term a number?
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
crates/hamgrd/src/actors/ha_set.rs
Outdated
| scope: dash_ha_set_config.scope.clone(), | ||
| vip_v4: dash_ha_set_config.vip_v4.as_ref().map(ip_to_string).unwrap_or_default(), | ||
| vip_v6: dash_ha_set_config.vip_v6.as_ref().map(ip_to_string), | ||
| owner: format!("{:?}", dash_ha_set_config.owner).into(), |
There was a problem hiding this comment.
We need proper conversion. I think the convention is removing prefix and changing to lower case.
crates/hamgrd/src/actors/ha_set.rs
Outdated
| use swss_common::SonicDbTable; | ||
| use swss_common_testing::*; | ||
|
|
||
| fn protobuf_struct_to_json<T: prost::Message + Default + serde::Serialize>(cfg: &T) -> HashMap<String, CxxString> { |
There was a problem hiding this comment.
The name is _to_json but actually it returns kfv
crates/hamgrd/src/actors/ha_scope.rs
Outdated
|
|
||
| // Implements internal action functions for HaScopeActor | ||
| impl HaScopeActor { | ||
| fn desired_ha_state_to_ha_role(desired_ha_state: i32) -> String { |
There was a problem hiding this comment.
I think it'd be better to move this function to sonic-dash-api-proto/src/lib.rs for helper functions around protobuf types
crates/hamgrd/src/actors/ha_scope.rs
Outdated
| send! { key: DashHaScopeConfigTable::table_name(), data: { "key": &scope_id, "operation": "Set", | ||
| "field_values": {"version": "1", "disable": "true", "desired_ha_state": "active", "approved_pending_operation_ids": "" }, | ||
| send! { key: HaScopeConfig::table_name(), data: { "key": &scope_id, "operation": "Set", | ||
| "field_values": {"json": "{\"version\":\"1\",\"disabled\":true,\"desired_ha_state\":2,\"approved_pending_operation_ids\":[]}"}, |
There was a problem hiding this comment.
Let's not use enum value here and below.
crates/hamgrd/src/db_structs.rs
Outdated
| Err(anyhow::anyhow!("DPU entry not found for slot {}", dpu_id)) | ||
| } | ||
|
|
||
| pub fn ip_to_string(ip: &IpAddress) -> String { |
There was a problem hiding this comment.
move to sonic-dash-api-proto crate
crates/hamgrd/src/db_structs.rs
Outdated
| } | ||
| } | ||
|
|
||
| pub fn decode_from_json_string<T: for<'de> serde::Deserialize<'de>>( |
There was a problem hiding this comment.
Is it better to move decode/encode function for protobuf objects to sonic-dash-api-proto? And the name should be from_field_values
crates/sonic-dash-api-proto/build.rs
Outdated
|
|
||
| proto_config.type_attribute( | ||
| "dash.ha_scope_config.HaScopeConfig", | ||
| "#[allow(unused_imports)] use sonicdb_derive::SonicDb;", |
There was a problem hiding this comment.
why allow(unused_imports)?
crates/hamgrd/src/actors/ha_scope.rs
Outdated
| impl HaScopeActor { | ||
| fn desired_ha_state_to_ha_role(desired_ha_state: i32) -> String { | ||
| match DesiredHaState::try_from(desired_ha_state) { | ||
| Ok(DesiredHaState::HaStateActive) => "active".to_string(), |
There was a problem hiding this comment.
Why the enum name is DesiredHaState not HaState based on protobuf? If HaState is used in another field, will it generate a different enum type in rust?
Can we use strum::Display to generate this function automatically?
There was a problem hiding this comment.
I see protobuf defines DesiredHaState type
There was a problem hiding this comment.
Jing will change the enums to follow proper naming convention: sonic-net/sonic-dash-api#42. With the change, I believe Prost will generate rust enum value without the common prefix. Then you can use strum::Display to generate above mapping.
crates/sonicdb-derive/src/lib.rs
Outdated
| true | ||
| } | ||
|
|
||
| fn convert_pb_to_json(kfv: &mut KeyOpFieldValues) { |
There was a problem hiding this comment.
Can this function be implemented in the trait instead of generated by macro? If is_proto returns false, it can do nothing as the default implementation. Then you don't fold expanded_proto into expanded to avoid duplicate code.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Moving SonicDbTable to sonic-dash-ha as part of sonic-net/sonic-dash-ha#82
Moving SonicDbTable to sonic-dash-ha as part of sonic-net/sonic-dash-ha#82
|
Cherry-pick PR to msft-202506: Azure/sonic-dash-ha.msft#13 |
~~Adding is_proto and convert_pb_to_json to SonicDbTable to support the changes in sonic-net/sonic-dash-ha#82 Moving SonicDbTable to sonic-dash-ha as part of sonic-net/sonic-dash-ha#82
~~Adding is_proto and convert_pb_to_json to SonicDbTable to support the changes in sonic-net/sonic-dash-ha#82 Moving SonicDbTable to sonic-dash-ha as part of sonic-net/sonic-dash-ha#82
~~Adding is_proto and convert_pb_to_json to SonicDbTable to support the changes in sonic-net/sonic-dash-ha#82 Moving SonicDbTable to sonic-dash-ha as part of sonic-net/sonic-dash-ha#82
~~Adding is_proto and convert_pb_to_json to SonicDbTable to support the changes in sonic-net/sonic-dash-ha#82 Moving SonicDbTable to sonic-dash-ha as part of sonic-net/sonic-dash-ha#82
Adding support for protobuf field values in DASH_HA_SET_CONFIG_TABLE and DASH_HA_SCOPE_CONFIG_TABLE